package com.itheima.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.itheima.dao.BookDao;
import com.itheima.domain.Book;
import com.itheima.service.BookService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class BookServiceImpl implements BookService {

    @Autowired
    private BookDao bookDao;

    /**
     * 新增用户
     * @param book
     * @return
     */
    @Override
    public boolean save(Book book) {
        return bookDao.insert(book) > 0 ;
    }

    /**
     * 根据id删除
     * @param id
     * @return
     */
    @Override
    public boolean delete(Integer id) {
        return bookDao.deleteById(id)>0;
    }

    /**
     * 查询所有
     * @return
     */
    @Override
    public List<Book> selectBook() {
        return bookDao.selectList(null);
    }

    /**
     *  根据id查询
     * @param id
     * @return
     */
    @Override
    public Book getById(Integer id) {
        return bookDao.selectById(id);
    }

    @Override
    public IPage<Book> getPage(int currentPage, int page) {
        //创建page对象 传入起始页参数 和查询条数3
        IPage page1 = new Page(currentPage,page);
        return bookDao.selectPage(page1,null);
    }

    /**
     * 修改
     * @param book
     * @return
     */
    @Override
    public boolean update(Book book) {
        return bookDao.updateById(book)>0;
    }
}
